package com.heima.behavior.properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;
@Configuration
public class KafkaProperties {
    @Value("${spring.kafka.bootstrap-servers}")
    private String ip;
    @Value("${spring.kafka.producer.key-serializer}")
    private String keySerializer;
    @Value("${spring.kafka.producer.value-serializer}")
    private String valueSerializer;
    @Value("${spring.kafka.producer.retries}")
    private String retries;
    @Bean
    public KafkaProducer<String,String> createKafkaProducer(){
        Properties properties = new Properties();
        properties.put("bootstrap.servers",ip);
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,keySerializer);
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,valueSerializer);
        properties.put(ProducerConfig.RETRIES_CONFIG,retries);
       return new KafkaProducer<String, String>(properties);
    }
}
